package com.ruoyi.APPMS.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.APPMS.domain.Vehiclesell;
import com.ruoyi.APPMS.service.IVehiclesellService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 车辆销售Controller
 *
 * @author 吴春梅
 * @date 2023-07-03
 */
@Api(tags="车辆销售控制器类")
@RestController
@RequestMapping("/vehiclesell/vehiclesell")
public class VehiclesellController extends BaseController
{
    @Autowired
    private IVehiclesellService vehiclesellService;

    /**
     * 查询车辆销售列表
     */
    @ApiOperation("查询车辆销售列表")
    @PreAuthorize("@ss.hasPermi('vehiclesell:vehiclesell:list')")
    @GetMapping("/list")
    public TableDataInfo list(Vehiclesell vehiclesell)
    {
        startPage();
        List<Vehiclesell> list = vehiclesellService.list(vehiclesell);
        System.out.println(list);
        return getDataTable(list);
    }

    /**
     * 导出车辆销售列表
     */

    @PreAuthorize("@ss.hasPermi('vehiclesell:vehiclesell:export')")
    @Log(title = "车辆销售", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Vehiclesell vehiclesell)
    {
        List<Vehiclesell> list = vehiclesellService.list(vehiclesell);
        ExcelUtil<Vehiclesell> util = new ExcelUtil<Vehiclesell>(Vehiclesell.class);
        util.exportExcel(response, list, "车辆销售数据");
    }

    /**
     * 获取车辆销售详细信息
     */
    @ApiOperation("获取车辆销售详细信息")
    @PreAuthorize("@ss.hasPermi('vehiclesell:vehiclesell:query')")
    @GetMapping(value = "/{vehicleid}")
    public AjaxResult getInfo(@PathVariable("vehicleid") Long vehicleid)
    {
        return success(vehiclesellService.listByid(vehicleid));
    }

    /**
     * 新增车辆销售
     */
    @PreAuthorize("@ss.hasPermi('vehiclesell:vehiclesell:add')")
    @Log(title = "车辆销售", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Vehiclesell vehiclesell)
    {
        return toAjax(vehiclesellService.save(vehiclesell));
    }

    /**
     * 车辆销售 生成订单
     */
    @ApiOperation("车辆销售 生成订单")
    @PreAuthorize("@ss.hasPermi('vehiclesell:vehiclesell:edit')")
    @Log(title = "车辆销售", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Vehiclesell vehiclesell)
    {
        vehiclesellService.createOrder2(vehiclesell);
        return toAjax(vehiclesellService.createOrder1(vehiclesell));
    }

    /**
     * 删除车辆销售
     */
    @PreAuthorize("@ss.hasPermi('vehiclesell:vehiclesell:remove')")
    @Log(title = "车辆销售", businessType = BusinessType.DELETE)
    @DeleteMapping("/{vehicleids}")
    public AjaxResult remove(@PathVariable List<Long> vehicleids)
    {
        return toAjax(vehiclesellService.removeByIds(vehicleids));
    }
}
